package com.gxa.p2p.controller;

import com.gxa.p2p.common.JsonResult;
import com.gxa.p2p.pojo.Expmark;
import com.gxa.p2p.pojo.Expmarklog;
import com.gxa.p2p.service.ExpmarkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author R
 * @data 2021-10-26 10:12
 */
@CrossOrigin
@Api("体验标控制层")
@RestController
@RequestMapping("/expMark")
public class ExpMarkController {

    @Autowired
    ExpmarkService expmarkService = null;
    /**
     * 饶贵钢
     * @param expmark
     * @return
     */
    @PostMapping("/addExpMark")
    @ApiOperation("新增体验标")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "expmark",value = "体验标信息",required = true,paramType = "body")
    })
    public Map addExpMark(Expmark expmark){
        expmarkService.addExpMark(expmark);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("添加成功");
        jsonResult.setCode("200");
        return jsonResult.getDataMap();
    }

    /**
     * 饶贵钢
     * @param page
     * @param size
     * @return
     */
    @PostMapping("/findExpMarkByPage")
    @ApiOperation("查询体验标")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页码",required = true,dataType = "int"),
            @ApiImplicitParam(name = "size",value = "每页记录数",required = true,dataType = "int")
    })
    public Map  findExpMarkByPage(Integer page,Integer size){
        List<Expmark> expMarkByPage = expmarkService.findExpMarkByPage(page, size);
        Integer expMarkCount = expmarkService.findExpMarkCount(page, size);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("查询成功");
        jsonResult.setCode("200");
        jsonResult.put("count",expMarkCount);
        jsonResult.setData(expMarkByPage);
        return jsonResult.getDataMap();
    }

    @PostMapping("/deleteExpMark")
    @ApiOperation("删除体验标")
    @ApiImplicitParam(name = "id",value = "id",required = true,dataType = "int")
    public Map deleteExpMark(Integer id){
        expmarkService.deleteExpMark(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("删除成功");
        return jsonResult.getDataMap();
    }

    /**
     * 饶贵钢
     * @param phone
     * @param name
     * @param userOrigin
     * @param page
     * @param size
     * @return
     */
    @PostMapping("/findExpMarkLogByPage")
    @ApiOperation("查询体验金记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone",value = "投资人手机号",required = false,dataType = "String"),
            @ApiImplicitParam(name = "name",value = "投资人名字",required = false,dataType = "String"),
            @ApiImplicitParam(name = "userOrigin",value = "用户来源",required = false,dataType = "String"),
            @ApiImplicitParam(name = "state",value = "状态",required = false,dataType = "String"),
            @ApiImplicitParam(name = "page",value = "页码",required = true,dataType = "int"),
            @ApiImplicitParam(name = "size",value = "每页记录数",required = true,dataType = "int")
    })
    public Map findExpMarkLogByPage(@RequestParam("phone") String phone,
                                    @RequestParam("name") String name,
                                    @RequestParam("userOrigin") String userOrigin,
                                    @RequestParam("state") String state,
                                    @RequestParam("page") Integer page,
                                    @RequestParam("size") Integer size){
        List<Expmarklog> expMarkLogByPage = expmarkService.findExpMarkLogByPage(phone, name, userOrigin, state, page, size);
        Integer expMarkLogCount = expmarkService.findExpMarkLogCount(phone, name, userOrigin, state, page, size);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("查询成功");
        jsonResult.setCode("200");
        jsonResult.put("count",expMarkLogCount);
        jsonResult.setData(expMarkLogByPage);
        return jsonResult.getDataMap();
    }

}
